/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.ultrasoft.farmasoft.domain;

import java.io.Serializable;
import java.util.Collection;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;

/**
 *
 * @author Administrador
 */
@Entity
@Table(name = "locality")
@NamedQueries({
    @NamedQuery(name = "Locality.findAll", query = "SELECT l FROM Locality l WHERE l.active = :active ORDER BY l.region.countryId.name, l.region.name, l.name"),
    @NamedQuery(name = "Locality.findByRegionId", query = "SELECT l FROM Locality l WHERE l.localityPK.regionId = :regionId"),
    @NamedQuery(name = "Locality.findByRegionIdBylocalityId", query = "SELECT l FROM Locality l WHERE l.localityPK.regionId = :regionId AND l.localityPK.localityId = :localityId"),
    @NamedQuery(name = "Locality.findByRegionIdByActive", query = "SELECT l FROM Locality l WHERE l.localityPK.regionId = :regionId AND l.active = :active"),
    @NamedQuery(name = "Locality.findByLocalityId", query = "SELECT l FROM Locality l WHERE l.localityPK.localityId = :localityId"),
    @NamedQuery(name = "Locality.findByName", query = "SELECT l FROM Locality l WHERE l.name = :name"),
    @NamedQuery(name = "Locality.findByInitials", query = "SELECT l FROM Locality l WHERE l.initials = :initials"),
    @NamedQuery(name = "Locality.findByArea", query = "SELECT l FROM Locality l WHERE l.area = :area"),
    @NamedQuery(name = "Locality.findByIdMaxLocality", query = "SELECT max(l.localityPK.localityId) FROM Locality l WHERE l.localityPK.regionId = :regionId"),
    @NamedQuery(name = "Locality.deleteByLocalityIdByRegionId", query = "DELETE FROM Locality l WHERE l.localityPK.regionId = :regionId AND l.localityPK.localityId = :localityId"),    
    @NamedQuery(name = "Locality.findByActive", query = "SELECT l FROM Locality l WHERE l.active = :active")})
public class Locality implements Serializable {
    private static final long serialVersionUID = 1L;
    @EmbeddedId
    protected LocalityPK localityPK;
    @Basic(optional = false)
    @Column(name = "name")
    private String name;
    
    @Column(name = "initials")
    private String initials;
    
    @Column(name = "area")
    private String area;
    
    @Basic(optional = false)
    @Column(name = "active")
    private boolean active;
    @OneToMany(mappedBy = "locality")
    private Collection<Pharmacy> pharmacyCollection;
    @OneToMany(mappedBy = "locality")
    private Collection<Provider> providerCollection;
    @JoinColumn(name = "regionId", referencedColumnName = "regionId", insertable = false, updatable = false)
    @ManyToOne(optional = false)
    private Region region;

    public Locality() {
    }

    public Locality(LocalityPK localityPK) {
        this.localityPK = localityPK;
    }

    public Locality(int regionId, short localityId, String name,String initials, String area,boolean active) {
    	this.localityPK= new LocalityPK(regionId, localityId);
        this.name = name;
        this.initials = initials;
        this.area = area;
        this.active = active;
    }

    public Locality(int regionId, short localityId) {
        this.localityPK = new LocalityPK(regionId, localityId);
    }

    public LocalityPK getLocalityPK() {
        return localityPK;
    }

    public void setLocalityPK(LocalityPK localityPK) {
        this.localityPK = localityPK;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getInitials() {
        return initials;
    }

    public void setInitials(String initials) {
        this.initials = initials;
    }

    public String getArea() {
        return area;
    }

    public void setArea(String area) {
        this.area = area;
    }

    public boolean getActive() {
        return active;
    }

    public void setActive(boolean active) {
        this.active = active;
    }

    public Collection<Pharmacy> getPharmacyCollection() {
        return pharmacyCollection;
    }

    public void setPharmacyCollection(Collection<Pharmacy> pharmacyCollection) {
        this.pharmacyCollection = pharmacyCollection;
    }

    public Collection<Provider> getProviderCollection() {
        return providerCollection;
    }

    public void setProviderCollection(Collection<Provider> providerCollection) {
        this.providerCollection = providerCollection;
    }

    public Region getRegion() {
        return region;
    }

    public void setRegion(Region region) {
        this.region = region;
    }
    
    @Override
    public int hashCode() {
        int hash = 0;
        hash += (localityPK != null ? localityPK.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Locality)) {
            return false;
        }
        Locality other = (Locality) object;
        if ((this.localityPK == null && other.localityPK != null) || (this.localityPK != null && !this.localityPK.equals(other.localityPK))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "com.ultrasoft.farmasoft.domain.Locality[ localityPK=" + localityPK + " ]";
    }
    
}
